home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libcairo-perl / examples / png / text-rotate.pl < prev    next >
Encoding:
Perl Script  |  2006-05-21  |  1.9 KB  |  87 lines

  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Cairo;
  6.  
  7. use constant
  8. {
  9.     WIDTH => 450,
  10.     HEIGHT => 900,
  11.     NUM_STRINGS => 3,
  12.     M_PI => 4 * atan2(1, 1),
  13. };
  14.  
  15. {
  16.     my $surface = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
  17.     my $cr = Cairo::Context->create ($surface);
  18.  
  19.     $cr->set_source_rgb (0.0, 0.0, 0.0);
  20.  
  21.     $cr->translate (40, 40);
  22.  
  23.     $cr->select_font_face ('mono', 'normal', 'normal');
  24.     $cr->set_font_size (12);
  25.     $cr->show_text ('+CTM rotation');
  26.  
  27.     $cr->save;
  28.     $cr->select_font_face ('serif', 'normal', 'normal');
  29.     $cr->set_font_size (40);
  30.     for (my $i = 0; $i < NUM_STRINGS; $i++) {
  31.         my $angle = $i * 0.5 * M_PI / (NUM_STRINGS - 1);
  32.         $cr->save;
  33.         $cr->rotate ($angle);
  34.         $cr->move_to (100, 0);
  35.         $cr->show_text ("Text");
  36.         $cr->restore;
  37.     }
  38.     $cr->restore;
  39.  
  40.     $cr->translate (0, HEIGHT / 3);
  41.  
  42.     $cr->move_to (0, 0);
  43.     $cr->show_text ('+CTM rotation');
  44.     $cr->rel_move_to (0, 12);
  45.     $cr->show_text ('-font rotation');
  46.  
  47.     $cr->save;
  48.     $cr->select_font_face ('serif', 'normal', 'normal');
  49.     $cr->set_font_size (40);
  50.     for (my $i = 0; $i < NUM_STRINGS; $i++) {
  51.         my $angle = $i * 0.5 * M_PI / (NUM_STRINGS - 1);
  52.         $cr->save;
  53.         $cr->rotate ($angle);
  54.         my $matrix = Cairo::Matrix->init_identity;
  55.         $matrix->scale (40, 40);
  56.         $matrix->rotate (-$angle);
  57.         $cr->set_font_matrix ($matrix);
  58.         $cr->move_to (100, 0);
  59.         $cr->show_text ('Text');
  60.         $cr->restore;
  61.     }
  62.     $cr->restore;
  63.  
  64.     $cr->translate (0, HEIGHT / 3);
  65.  
  66.     $cr->move_to (0, 0);
  67.     $cr->show_text ('+CTM rotation');
  68.     $cr->rel_move_to (0, 12);
  69.     $cr->show_text ('-CTM rotation');
  70.  
  71.     $cr->save;
  72.     $cr->select_font_face ('serif', 'normal', 'normal');
  73.     $cr->set_font_size (40);
  74.     for (my $i = 0; $i < NUM_STRINGS; $i++) {
  75.         my $angle = $i * 0.5 * M_PI / (NUM_STRINGS - 1);
  76.         $cr->save;
  77.         $cr->rotate ($angle);
  78.         $cr->move_to (100, 0);
  79.         $cr->rotate (-$angle);
  80.         $cr->show_text ('Text');
  81.         $cr->restore;
  82.     }
  83.     $cr->restore;
  84.  
  85.     $surface->write_to_png ('text-rotate.png');
  86. }
  87.